﻿var googleMaps = (function () {
    var map;
    function initialize(points) {
        var mapOptions = {
            zoom: 7,
            center: new google.maps.LatLng(42.5, 25),
            mapTypeId: google.maps.MapTypeId.TERRAIN
        };
        map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions);
        addMarkersAndPolylines(points);
    }

    function addMarker(latitude,longitude,message){
        var position = new google.maps.LatLng(latitude, longitude);
        var marker = new google.maps.Marker({
            position: position,
            map: map,
            title: message
        });
    }

    function addMarkersAndPolylines(points) {
        var googleMapsPoints = [];
        for (var i = 0; i < points.length; i++) {
            addMarker(points[i].Point.Latitude, points[i].Point.Longitude, points[i].Message);
            googleMapsPoints.push(new google.maps.LatLng(points[i].Point.Latitude, points[i].Point.Longitude));
        }
        addPolyline(googleMapsPoints);
    }

    function addPolyline(googleMapsPoints) {
        var path = new google.maps.Polyline({
            path: googleMapsPoints,
            strokeColor: '#FF0000',
            strokeOpacity: 1.0,
            strokeWeight: 2
        });

        path.setMap(map);
    }

    return {
        initialize: initialize,
        addMarkersAndPolylines: addMarkersAndPolylines
    }
})();